package com.volunteer.service.Impl;

import com.baidu.aip.ocr.AipOcr;
import com.volunteer.service.PhotoDealService;
import com.volunteer.util.Constants;
import com.volunteer.util.ResponseResult;
import com.volunteer.util.Result;
import org.json.JSONObject;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * @author willow
 * @version v.0.1
 * @date 2018年08月11日
 */
@Service
public class PhotoDealServiceImpl implements PhotoDealService {
    @Override
    public Result identifyPhotoWords(String photoAddress) {
        // 初始化一个AipOcr
        AipOcr client = new AipOcr(Constants.BAIDU_PHOTO_APP_ID, Constants.BAIDU_PHOTO_API_KEY, Constants.BAIDU_PHOTO_SECRET_KEY);
        // 调用接口
        JSONObject res = client.basicGeneral(photoAddress, new HashMap<>());
        try {
            System.out.println(res.toString(2));
            return ResponseResult.genSuccessResult(res.toString(2));
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return ResponseResult.genFailResult(Constants.DEFAULT_FAIL_REQUEST_FAILED);
        }
    }
}
